<%@page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%><!DOCTYPE HTML>
<html>
<head>
<style type="text/css">
	.tree-node {padding:0;}
</style>
  </head>
  <body>
  	<div class="easyui-layout" data-options="fit:true">
		<div data-options="region:'north',border:false">
			<fieldset>
    		<legend>过滤条件</legend>
    		<table style="width:100%">
    			<tr>条件查询</tr>
    		</table>
  		</fieldset>
		</div>
  		<div data-options="region:'center',border:false" style="padding-bottom: 33px">
  		
  			<div class="easyui-layout" data-options="fit:true">
                <div data-options="region:'north',split:true,title:'圈子信息'" style="height:300px">
					<table id="group_grid"></table>              
                </div>
                <div data-options="region:'center',title:'圈子成员信息' " style="padding-bottom: 33px">
                	<div id="user_grid_toolbar" class="toolbar"></div>
                	<table id="user_grid"></table>
                </div>
            </div>
  		
		</div>
		
	</div>
	<script>
		$(function(){
			$('#user_grid_toolbar').toolbar({buttons:[
	           	{name:'add',iconCls:'icon-add',text:'添加成员'},
	      	],handler:handler});
			
			//成员信息
			$('#user_grid').datagrid({
				pagination:true,singleSelect:true,rownumbers:true,striped:true,fitColumns:true,fit:true,
			    columns:[[
			    	{field:'nickname',title:'姓名'},
					{field:'username',title:'用户名'},
					{field:'type',title:'用户类型',formatter:function(v,r,i){
						return $codetext('userType',v)
					}},
					{field:'createdDt',title:'创建时间'},
					{field:'createdBy',title:'创建人'},
					{field:'updatedDt',title:'更改时间'},
					{field:'updatedBy',title:'更改人'},
					{field:'enabled',title:'启用标记',formatter:$g.bv},
					{field:'-',title:'操作',formatter:function(v,r,i){
						return '<a href="#" onclick="toDel('+r.id+');">删除</a>'
					}}
			    ]]
			});
			
			$('#group_grid').datagrid({
		    	url:'/group/info/page',
	    		pagination:true,
	    		singleSelect:true,
	    		rownumbers:false,
	    		striped:true,
	    		fit:true,
	    		fitColumns:true,
	    		toorbar:'#toolbar_group',
	    		columns:[[
	    			{field:'ck',checkbox:true},
	    			{field:'id',title:'编号'},
	    			{field:'groupName',title:'名称'},
	    			{field:'groupNote',title:'备注'},
	        		{field:'createdDt',title:'创建时间'},
	        		{field:'updatedDt',title:'更新时间'},
	    		]],
	    		onSelect:loadMember
			 });
			//加载成员信息
			function loadMember(index,row){
				console.log(index);
				console.log(row);
				var param = {};
		    	param.groupId = row.id;
		    	$('#user_grid').datagrid({ 
		    		queryParams: param,
		    		url:"groupUserpage"
		    	}); 
			}
			
			
		});
		
		function handler() {
			if(this.name == 'search') return toSearch();
			var item = $('#group_grid').datagrid('getSelected');
			if(!item) return;
			if(this.name == 'add') return toEdit(item);
			switch(this.name) {
			case 'addSub': add(item);break;
			case 'edit': toEdit(item);break;
			}
		}

		function toEdit(item) {
			show({code:'group_member_edit',title:'编辑用户信息',iconCls:'icon-edit',uri:'edit?id='+item.id,width:800,height:600,
				options : {
					success : function(data) { 
						$('#user_grid').datagrid('reload'); 
					}
				}
			});
		}
		
		function toDel(id) {
			var item = $('#group_grid').datagrid('getSelected');
			var param = {};
	    	param.groupId = item.id;
	    	param.userId = id;
			$confirm('您确定要删除该成员吗？',function() {
				$.post('deleteBygroupIdAndUserId',param,function(r) {
					if(r.code <= 0) return $error(r.msg);
					$('#user_grid').datagrid('reload');
					$prompt('删除成功');
				},'json');
			});
		}
		
	</script>
  </body>
</html>